using System;
using System.Collections.Generic;

namespace Com.ContentRendering.Api.DataEngine.Handler.Self
{
    /// <summary/>
    internal class CachedKeyedCollectionSelfHandler : AbstractSelfHandler
    {
        /// <summary/>
        internal CachedKeyedCollectionSelfHandler(
            ReflectionCache reflectionCache,
            object value)
            : base(
            reflectionCache,
            value) { }

        /// <summary/>
        internal override IEnumerator<object> Parse()
        {
            Type type = base._value.GetType();

            // has it NOT been cached
            if (!base._reflectionCache.IsDictionaryFlagValid(type))
            {
                return base._successor.Parse();
            }
            
            List<object> parsedValues = new List<object>();

            // append the single item to the list
            parsedValues.Add(this._value);

            return parsedValues.GetEnumerator();
        }
    }
}

